﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EditUserUserControl.ascx.cs"
    Inherits="JM.JCY.SharePointComponent.UserManagement.EditUser.EditUserUserControl" %>
<%@ Register Src="../LeftMenu/LeftMenuUserControl.ascx" TagName="LeftMenuUserControl"
    TagPrefix="uc1" %>
<script language="javascript" type="text/javascript">

    $(document).ready(function () {

        var imgCancel = $("#<%=imgCancel.ClientID %>");
        imgCancel.live('click', function () {
            location.href = "StaffMgr.aspx";
            return false;
        });
    });

    $(function () {
        var $ddlDept = $("select[name$=ddlDept]");
        var $ddlTitle = $("select[name$=ddlJobTitle]");
        $ddlDept.focus();
        $ddlDept.bind("change keyup", function () {
            if ($(this).val() != "0") {
                loadJobTitle($("select option:selected")[1].value);
                $ddlTitle.fadeIn("slow");
            } else {
                $ddlTitle.fadeOut("slow");
            }
        });
    });

    function loadJobTitle(selectedItem) {
        $.support.cors = true;
        $.ajax({
            type: "GET",
            url: UserManagementServiceUrl + "GetTitleByDeptId?deptId=" + selectedItem,
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            async: false,
            cache: false,
            success: function Success(data) {
                var jsonp = eval('(' + data + ')');
                printJobTitle(jsonp);
            }
        });
    }



    function printJobTitle(data) {
        $("select[name$=ddlJobTitle] > option").remove();
        $("select[name$=ddlJobTitle]").append("<option value='0'>请选择一个职位...</option>")
        for (var i = 0; i < data.length; i++) {
            $("select[name$=ddlJobTitle]").append("<option value=" + data[i].ID + ">" + data[i].JobTitle + "</option>");


        }
    }
      
</script>
<script type="text/javascript">



    $(document).ready(function () {
        var imgCancel = $("#<%=imgCancel.ClientID %>");
        imgCancel.live('click', function () {
            location.href = "StaffMgr.aspx";
            return false;
        });

        var imgSave = $("#<%=imgSave.ClientID %>");

        imgSave.live('click', function () {

            var ctl = document.getElementById('<%=GridViewDeptList.ClientID %>');
            if (ctl == undefined) {

                alert('请至少选择一个部门.');

                return false;
            }
        });

        var ImgInsert = $("#<%=ImgInsert.ClientID %>");
        ImgInsert.live('click', function () {

            var deptId = 0;
            var jobTitleId = 0;
            var deptName = "";
            var jobTitle = ""

            if (($("#<%=ddlDept.ClientID %>").val() != 0) && ($("#<%=ddlJobTitle.ClientID %>").val() != 0)) {
                deptId = $("#<%=ddlDept.ClientID %> option:selected").val();
                deptName = $("#<%=ddlDept.ClientID %> option:selected").text();

                jobTitleId = $("#<%=ddlJobTitle.ClientID %> option:selected").val();
                jobTitle = $("#<%=ddlJobTitle.ClientID %> option:selected").text();

                CallServer(1 + "|Y" + "@&@" + deptId + "@&@" + jobTitleId + "@&@" + deptName + "@&@" + jobTitle, 'content');
                return false;
            }
            else if ($("#<%=ddlDept.ClientID %>").val() == 0) {
                alert('请选择部门.');
                return false;
            }

            else if ($("#<%=ddlJobTitle.ClientID %>").val() == 0 || $("#<%=ddlJobTitle.ClientID %>").val() == null) {
                alert('请选择职位.');
                return false;
            }

        });

        var lbdelete = $("#<%= lkbRemove.ClientID %>");
        lbdelete.live('click', function () {

            showConfirm('', '请确认要删除被选中的用户，一旦删除将无法恢复?', RemoveUserDoCall, null, true);
            return false;
        });

    });

    function RemoveUserDoCall() {
        __doPostBack('DeleteUserById', '');
    }

    function ReceiveCallback(arg, context) {
        if (arg != "") {
            var r = arg.split("|@|@|@");
            var container = document.getElementById(context);
            container.innerHTML = r[0];

        }
    }

    function DeleteUserDept(jobTitleId) {

        CallServer(1 + "|Y" + "@&@" + jobTitleId, 'content');
        return false;

    }
</script>
<div>
    <table class="main">
        <tr>
            <td valign="top" width="25%" runat="server" id="tdLeftMenu">
                <uc1:leftmenuusercontrol id="LeftMenuUserControl1" runat="server" />
            </td>
            <td valign="top" width="75%" runat="server" id="tdContent">
                <table class="content" width="98%">
                    <tr>
                        <td style="padding: 5px;">
                            <table width="100%" class="title">
                                <tr>
                                    <td width="60%">
                                        <h2 class="title">
                                            <asp:Label ID="lblTitle" runat="server" Text="编辑用户"></asp:Label>
                                        </h2>
                                    </td>
                                    <td align="right" width="40%">
                                        <img src="/_layouts/JM.JCY.Resource/images/delete.png" width="12"/><asp:LinkButton ID="lkbRemove"
                                            runat="server">删除该用户</asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <br />
                            <hr />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <table width="100%" class="form">
                                <tr>
                                    <td width="26%">
                                        <b>姓名</b>
                                    </td>
                                    <td width="1%">
                                        :
                                    </td>
                                    <td width="73%">
                                        <%--<asp:TextBox ID="txtName" runat="server" MaxLength="100" Width="330"></asp:TextBox>--%>
                                        <asp:Label ID="lblName" runat="server"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td width="26%">
                                        <b>性别</b>
                                    </td>
                                    <td width="1%">
                                        :
                                    </td>
                                    <td width="73%">
                                        <asp:RadioButtonList ID="rbGender" runat="server" RepeatDirection="Horizontal">
                                            <asp:ListItem Value="男">男</asp:ListItem>
                                            <asp:ListItem Value="女">女</asp:ListItem>
                                        </asp:RadioButtonList>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <b>部门科室</b>
                                    </td>
                                    <td>
                                        :
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlDept" runat="server" AppendDataBoundItems="true" Width="340">
                                            <asp:ListItem Text="请选择一个部门..." Value="0" Selected="True" />
                                        </asp:DropDownList>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <b>职位</b>
                                    </td>
                                    <td>
                                        :
                                    </td>
                                    <td>
                                        <asp:DropDownList ID="ddlJobTitle" runat="server" Width="340">
                                        </asp:DropDownList>
                                        <asp:ImageButton ID="ImgInsert" runat="server" ImageUrl="~/_layouts/JM.JCY.Resource/images/add.png" />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                        <div id="content" style="padding-left: 7px">
                                            <asp:GridView ID="GridViewDeptList" runat="server" AutoGenerateColumns="false" CssClass="list"
                                                GridLines="None" OnRowDataBound="GridViewDeptList_RowDataBound" Width="100%"
                                                DataKeyNames="JobTitleId">
                                                <Columns>
                                                    <asp:BoundField DataField="DeptName" HeaderText="部门科室" HeaderStyle-Width="35%" HeaderStyle-HorizontalAlign="Left">
                                                        <HeaderStyle HorizontalAlign="Left" Width="35%"></HeaderStyle>
                                                    </asp:BoundField>
                                                    <asp:BoundField DataField="JobTitle" HeaderText="职位" HeaderStyle-Width="65%" HeaderStyle-HorizontalAlign="Left">
                                                        <HeaderStyle HorizontalAlign="Left" Width="65%"></HeaderStyle>
                                                    </asp:BoundField>
                                                    <asp:TemplateField>
                                                        <ItemTemplate>
                                                            <asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="~/_layouts/JM.JCY.Resource/images/delete.ico"
                                                                CommandArgument='<%# Eval("JobTitleId") %>' />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="DeptId" Visible="false" />
                                                    <asp:BoundField DataField="JobTitleId" Visible="false" />
                                                </Columns>
                                            </asp:GridView>
                                        </div>
                                    </td>
                                </tr>
                                 <tr>   <td colspan=3><hr id="hr2" /></td></tr>
                                     <tr>

                                    <td>
                                          <b>分管部门</b>
                                    </td>
                                    <td>
                                        :
                                    </td>
                                    <td>
                                        <asp:CheckBoxList ID="cblDept" runat="server" RepeatColumns="2">
                                        </asp:CheckBoxList>
                                    </td>
                                </tr>
                                     <tr>   <td colspan=3><hr id="hr1" /></td></tr>
                                <tr>
                                    <td>
                                        <b>状态</b>
                                    </td>
                                    <td>
                                        :
                                    </td>
                                    <td>
                                        <asp:RadioButtonList ID="rblStatus" runat="server" RepeatDirection="Horizontal">
                                            <asp:ListItem Value="激活" Selected="True">激活</asp:ListItem>
                                            <asp:ListItem Value="未激活">未激活</asp:ListItem>
                                        </asp:RadioButtonList>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:ImageButton ID="imgSave" runat="server" ImageUrl="~/_layouts/JM.JCY.Resource/images/save.png"
                                OnClick="imgSave_Click" />
                            <asp:ImageButton ID="imgCancel" runat="server" ImageUrl="~/_layouts/JM.JCY.Resource/images/cancel.png" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>
<asp:HiddenField ID="hfUserId" runat="server" />
